<style lang=stylus scoped>
main.pug
  list-style none
  margin auto
  max-width 41em
  padding 0 2em 20vh
main.pug /deep/
  &>main
    &>h2.date
      font-size 1.4em
      padding-top 0.2rem
      text-shadow 1px 1px 0 #aaa
      margin 0
      justify-content space-between
      b.date
        width 3.4em
        padding-right 0.4em
        justify-content space-between
        display flex
    &>h2.date:first-child
      padding-top 0.2rem
      margin-top 0
    &>li
      margin-top 1.5rem
    &>li>section
      margin-top 1rem
    &>li>a.h2
      font-family html
      font-size 1.25rem
      line-height 1.35
      text-shadow 1px 1px 0 #eee
      font-weight bold
      color #000
      position relative
      padding-bottom 0.6rem
    &>li>a.h2:after, &>li>a.h2:before
      border-top 1px solid #f50
      content ''
      position absolute
      left 0
      bottom 0
    &>li>a.h2:before
      width 200%
      border-image linear-gradient(90deg, #333, #eee 20%, transparent)
      border-image-slice 10
      transform scale(0.5)
      transform-origin 0 0
    &>li>a.h2:after
      width 0
      transition all 0.5s
    &>li>a.h2:hover
      color #f50
      text-shadow none
    &>li>a.h2:hover:after
      width 100%
</style>


<template lang=pug>
main.pug(ref="m")
</template>


<script lang=ls>
import
  \@/ls/html/pug
  \@/ls/db/cache : {by-hash}
  \@/ls/html/md-load
  \@/ls/html/md

export default _ = pug(
  \li
  * data:~>
      {
        li:[]
      }
  (li)!->
    var pre
    for i in li.split("\n")
      [file, hash] = i.split(",")
      for i in (await by-hash "li/#file.md", hash).split("\n------\n")
        pos = i.indexOf("\n")
        url = i.slice(0,pos)
        url = url.slice(url.indexOf("/"))
        [h1,brief,meta] = md-load i.slice(pos+1), (txt)~>[txt]
        date = meta['日期']
        if date and date.charAt(0) != '-'
          month = date.slice(0,7)
          if pre!=month
            pre = month
            @li.push month
        @li.push [
          url
          date
          meta['作者']
          h1
          md brief, "//"+location.host+url
        ]
    #pre_month = ''
    #li = _split li

    #pos = 0
    #push = ~>
    #  t = []
    #  pos-next = pos + 5
    #  li-t = li.slice(pos, pos-next)
    #  for [url,hash] in li-t
    #    t.push li-get url, hash
    #  t = await Promise.all t
    #  toadd = []
    #  for [url,hash,time],n in li-t
    #    if time > 0
    #      date = new Date(time*1000).toISOString().slice(0,19).replace("T",' ')
    #      m = date.slice(0,7)
    #      if m != pre_month
    #        pre_month := m
    #        toadd.push m
    #    else
    #        date = 0
    #    toadd.push [url,date].concat t[n]
    #  @li.splice @li.length, toadd.length, ...toadd
    #  pos := pos-next

    ## 预先加载6篇，防止页面抖动
    #await push!
    #do ~>
    #  while pos < li.length
    #    await push!

  (url)~>
    $get(
      url+\.csv
    )
)

</script>
